<style>
</style>
<template>
  <list_url_scroll ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url_scroll>
</template>
<script>
export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');
    let name = this.$get('name');
    let forms_config = {};
    let list_cols = {};
    let api = "", title = "", handle_res;
    switch (name) {
      case "tysd_store": {
        api = 'http://edu.taiyushangdao.com/wap/store/getproductlist';
        title = "太禹商道-商品";
        handle_res = function (res){
          if (typeof res == "string") res = JSON.parse(res);
          return {
            data: {list:res.data, count: 0},
            message: "",
          }
        }
        forms_config = {
          keyword: {label:'商品名称',name:'keyword',type:'text_one',value:''},
          cid: {label:'商品分类',name:'cId',type:'select_one',config:[],value:''},
        }
        forms_config["keyword"] = {label:'关键词',name:'keyword',type:'text_one',value:''};
        list_cols = {
          id: {name:'id', label:'ID', width:'65px', fixed:'left'},
          store_name: {name:'store_name', label:'商品名称', min_width:'120px'},
          image: {name:'image', label:'头图', width:'60px', type:'file_img'},
          sales: {name:'sales', label:'销量', width:'100px'},
          stock: {name:'stock', label:'库存', width:'100px'},
          price: {name:'price', label:'价格', width:'100px'},
        }
      }
    }

    return {
      config_name: name,
      config: {
        api: '/home/api/curl?_url='+encodeURIComponent(api),
        title: title,
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        handle_res: handle_res,
        limit: 20,
        p: this.$get('p', 1),
        p_key: "page",
        n_key: "limit",
        p_start_1: true,
      },
    }
  },
  methods: {
    curl(op, ok, fail){
      if (typeof(op)=="string") op.url = op;
      op.url = '/home/api/curl?_url='+encodeURIComponent(op.url);
      return ajax(op, ok, fail);
    },
    to_edit(row){
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

    switch (this.config_name){
      case "tysd_store":{
        let cid_map = [{value:'', content:'全部'}];
        app.curl({url:"http://edu.taiyushangdao.com/wap/store/getcategory.html"}, (res)=>{
          if (typeof(res)=="string") res = JSON.parse(res);
          res.data.forEach((v)=>{
            cid_map.push({value:v.id, content:v.cate_name});
          })
          app.config.forms_config.cid.config = cid_map;
        })
      }
    }
  }
}
</script>
